package cn.curtain.girl.service;

import cn.curtain.girl.domain.Girl;
import cn.curtain.girl.exception.GirlException;
import cn.curtain.girl.repository.GirlRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.annotation.Secured;
import org.springframework.stereotype.Service;
import javax.transaction.Transactional;

@Service
public class GirlService {

    @Autowired
    private GirlRepository girlRepository;

    //事务管理
    @Transactional
    public void insertTwo(){
        Girl girlA = new Girl();
        girlA.setAge(18);
        girlA.setCup("A");
        girlRepository.save(girlA);

        int x = 2/0;
        Girl girlB = new Girl();
        girlB.setAge(19);
        girlB.setCup("C");
        girlRepository.save(girlB);

    }


    public void getAge(Integer id)throws Exception{
        Girl girl = girlRepository.findOne(id);
        Integer age = girl.getAge();
        if(age<10){
            throw new GirlException(100,"你还在上小学吧");
        }else if(age>10&&age<16){
            throw new GirlException(101,"你还在上初中吧");
        }

    }
}
